package com.atguigu.gulimall.search.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadTest002pool {
    public static ExecutorService executorService = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws Exception{
        System.out.println("main...........start........");
//        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
//            System.out.println("当前线程：" + Thread.currentThread().getId());
//            int i = 10 % 3;
//            System.out.println("运行结果：" + i);
//        }, executorService);
        //        方法执行后的感知
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            System.out.println("当前线程：" + Thread.currentThread().getId());
            int i = 10 % 0;
            System.out.println("运行结果：" + i);
            return i;
        }, executorService).whenComplete((result,exception)->{
            System.out.println("异步任务成功完成了。。。结果是："+result+"、异常是："+exception);
        }).exceptionally(throwable -> {
            return 10;
        });
        System.out.println("main...........end........"+future.get());
    }
    public  void thread(String[] args) {
        System.out.println("main...........start........");
        Thread01 thread01 = new Thread01();
        thread01.start();
        System.out.println("main...........end........");
    }
    public static class Thread01 extends Thread{
        @Override
        public void run() {
            System.out.println("当前线程："+Thread.currentThread().getId());
            int i = 10%3 ;
            System.out.println("运行结果："+i);
        }
    }
}